package com.lwj.controller;

import com.github.pagehelper.PageInfo;
import com.lwj.dao.UserMapper;
import com.lwj.entity.Project;
import com.lwj.entity.User;
import com.lwj.service.UserService;
import com.lwj.util.DataRet;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import javax.net.ssl.HttpsURLConnection;
import javax.servlet.http.HttpSession;
import javax.xml.crypto.Data;
import java.util.List;

/**用户相关
 * Created by LWJ on 2018/4/25.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录验证
     * @param user
     * @return
     */
    @PostMapping("/login")
    public DataRet<User> getUser(User user,HttpSession session,int role){
        return userService.getUser(user,session,role);
    }

    @GetMapping("")
    public DataRet<User> getUserByName(String name){
        return userService.getUserByUserName(name);
    }

    @PostMapping("/register")
    public DataRet<String> registerUser(User user){
        return null;
    }

    @PostMapping("/searchRes")
    public PageInfo<User> getSearchRes(HttpSession session, @RequestParam(value = "pageNo",defaultValue ="1" )int pageNo, @RequestParam(value = "pageSize",defaultValue ="1" )int pageSize,String searchmethod){
        return userService.searchUser((String) session.getAttribute("userName"),pageNo,pageSize);
    }

    @GetMapping("/findAll")
    public PageInfo<User> findAll(@RequestParam(value = "pageNo",defaultValue ="1" )int pageNo, @RequestParam(value = "pageSize",defaultValue ="1" )int pageSize){
        return userService.searchUser("",pageNo,pageSize);
    }

    @PostMapping("/searchByTypeId")
    public PageInfo<User> getProjectByType(@RequestParam(value = "pageNo",defaultValue ="1" )int pageNo, @RequestParam(value = "pageSize",defaultValue ="1" )int pageSize, int typeId){
        return userService.getUserByType(pageNo,pageSize,typeId);
    }
}